package com.zx.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zx.entity.Classes;
import com.zx.entity.Student;
import com.zx.service.StudentService;
import com.zx.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/StudentServlet")
public class StudentServlet extends BaseServlet{
    StudentService studentService = new StudentServiceImpl();
    public void selectBycid (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收要修改的id编号
        String cid = request.getParameter("cid");
        System.out.println(cid);
        List<Student> studentList = studentService.selectBycid(Integer.parseInt(cid));

        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(studentList);
        writer.print(json);
        writer.close();
    }
}
